package com.books.mapper.common;

import com.books.model.entity.backcontroller.Announcement;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 * 公告
 *
 * @Author 饿熊的咆哮
 * @Date 2021/9/28 13:53
 * @Version 1.0
 */
@Mapper
public interface AnnouncementMapper {
    @Select("select * from announcement order by announcement_id desc")
    List<Announcement> findAll();

    /**
     * 根据公告id查询
     * @param announcementId
     * @return
     */
    @Select("select * from announcement where announcement_id = #{announcementId}")
    Announcement findByAnnouncementId(Integer announcementId);

    /**
     * 根据标题模糊查询
     * @param announcementTitle
     * @return
     */
    @Select("select * from announcement where announcement_title like '%${announcementTitle}%'")
    List<Announcement> findByAnnouncementTitle(String announcementTitle);

    /**
     * 根据管理员id查询谁发布的
     * @param adminId
     * @return
     */
    @Select("select * from announcement where admin_id = #{adminId}")
    List<Announcement> findByAdminId(Integer adminId);

    /**
     * 添加
     * @param announcement
     */
    @Insert("insert into announcement values(null,#{announcementTitle},#{sendTime},#{adminId},#{content})")
    void addAnnouncement(Announcement announcement);

    @Delete("delete from announcement where announcement_id=#{announcementId}")
    void delByAnnouncementId(Integer announcementId);
}
